home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / me_cd25.zip / MUTT2.ZIP / TAGS.MUT < prev    next >
Text File  |  1992-11-09  |  2KB  |  104 lines

  1.  ;; Lookup stuff in a tags file
  2.  
  3.  ;; To create a tags file in:
  4.  ;;   current directory: ctags -xtw files.[ch] >Tags
  5.  ;;   a subtree: find . -name '*.[ch]' -print | xargs ctags -xtw >Tags
  6.  ;; Keep the tags file in the directory it is created in
  7.  
  8.  ;; C Durland    Public Domain
  9.  
  10. (include me2.h)
  11.  
  12. (string tags-path   file-name text)
  13. (int tag-buffer)
  14. (bool loaded-tags)
  15.  
  16. (defun
  17.   MAIN
  18.   {
  19.     (bind-to-key "goto-tag"    "M-.")        ;; GNU binding
  20.   }
  21. )
  22.  
  23. (defun
  24.   lookup-tag (string tag) HIDDEN    ; search the tags buffer for a tag
  25.   {
  26.     (bool s)(int cb)
  27.  
  28.     (if (not loaded-tags) { (msg "No tags!  Run select-tag-file.")(done) })
  29.  
  30.     (msg "Looking for tag ...")
  31.  
  32.     (s TRUE)
  33.     (cb (current-buffer))
  34.     (current-buffer tag-buffer)(beginning-of-buffer)
  35.     (if (re-search-forward (concat '^' tag '\ '))
  36.       {
  37.     (looking-at '\ *\d+ \([^ ]+\)\ +\(.+\)')
  38.     (file-name (get-matched '\1'))
  39.     (text (get-matched '\2'))
  40.       }
  41.       { (msg tag " not found.")(s FALSE) }
  42.     )
  43.     (current-buffer cb)
  44.     s
  45.   }
  46.   get-tag-name HIDDEN
  47.   {
  48.     (string tag)
  49.  
  50.     (if (== "" (tag (ask "Tag to look for: ")))
  51.       { (looking-at '\w+')(get-matched '&') }
  52.       tag
  53.     )
  54.   }
  55.   goto-tag
  56.   {
  57.     (string tag)
  58.  
  59.     (tag (get-tag-name))
  60.     (if (lookup-tag tag)
  61.     {
  62.       (visit-file (concat tags-path "/" file-name))
  63.       (if (search-forward text)
  64.         { (arg-prefix 1)(reposition-window) }    ; move to top of screen
  65.     (msg "Tag file is out of date.")
  66.       )
  67.     })
  68.   }
  69.   where-is-tag
  70.   {
  71.     (string tag)
  72.  
  73.     (tag (get-tag-name))
  74.     (if (lookup-tag tag)
  75.     (msg tag " is in " tags-path "/" file-name))
  76.   }
  77.   select-tag-file MAIN
  78.   {
  79.     (int cb)
  80.     (string tags-file)
  81.  
  82.     (loaded-tags FALSE)
  83.  
  84.     (tags-path (complete CC_FNAME "DIRECTORY tags file is in: "))
  85.     (tags-file (concat tags-path "/Tags"))
  86.  
  87.     (if (not (file-exists tags-file))
  88.     { (msg "No such tags file: " tags-file)(done) })
  89.  
  90.     (cb (current-buffer))
  91.  
  92.     (if (== -2 (tag-buffer (attached-buffer "*TAGS*")))
  93.     (tag-buffer (create-buffer "*TAGS*" BFHooHum)))
  94.     (current-buffer tag-buffer)
  95.     (clear-buffer)
  96.  
  97.     (read-file tags-file)
  98.  
  99.     (current-buffer cb)
  100.     (loaded-tags TRUE)
  101.     (msg "Loaded tags")
  102.   }
  103. )
  104.